#include <iostream>
#include <vector>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    string s;
    cin >> s;
    int l = -1;
    for(auto ch : s) if(ch == 'L') l++;
    int r = l + 1, ot = 1;
    vector<int> ans(n);
    for(int i = n - 1; i >= 0; i--) {
        if(s[i] == 'L'){
            ot = (ot * a[l--]) % m;
        }else{
            ot = (ot * a[r++]) % m;
        }
        ans[i] = ot;
    }
    for(auto x : ans) cout << x << ' ';
    cout << '\n';
}

int main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}